package com.taichuan.selfcheck.ui.fragment;


import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import com.taichuan.selfcheck.R;
import com.taichuan.selfcheck.mvp.presenter.EmptyPresenter;
import com.taichuan.selfcheck.mvp.viewinterface.EmptyInterface;
import com.taichuan.selfcheck.ui.activity.MainActivity;
import com.taichuan.selfcheck.ui.fragment.base.AppBaseFragment;
import com.taichuan.tcutils.taichuan.SystemUtils;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * 摄像头测试
 */
public class SelectCameraFragment extends AppBaseFragment<EmptyInterface, EmptyPresenter> implements EmptyInterface {
    private static final String TAG = SelectCameraFragment.class.getSimpleName();

    @BindView(R.id.camera_infrared_test_button)
    Button infraredCameraBtn;
    @BindView(R.id.camera_color_test_button)
    Button colorCameraBtn;
    @BindView(R.id.camera_take_photo_test_button)
    Button takePhotoCameraBtn;
    private MainActivity mMainActivity;


    @Override
    protected boolean isAllowAutoFinishFragment() {
        return false;
    }

    @Override
    public void doOnAutoFinishFragment() {
        operateFragmentManagerBack();
    }

    @Override
    protected void getBundleValues(Bundle bundle) {

    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        switch (event.getKeyCode()){
            case KeyEvent.KEYCODE_1:
                colorCameraBtn.performClick();
                break;
            case KeyEvent.KEYCODE_2:
                infraredCameraBtn.performClick();
                break;
        }
        return super.dispatchKeyEvent(event);
    }

    @Override
    protected int setContentViewId() {
        return R.layout.fragment_select_camera;
    }

    @Override
    protected void initView(View view, Bundle bundle) {
        if (SystemUtils.isVankeSiteBoxDevice()){
            takePhotoCameraBtn.setVisibility(View.VISIBLE);
        }else {
            takePhotoCameraBtn.setVisibility(View.GONE);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mMainActivity = (MainActivity) context;
    }

    @Override
    protected EmptyPresenter createPresenter() {
        return new EmptyPresenter();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @OnClick({R.id.camera_color_test_button, R.id.camera_infrared_test_button,R.id.camera_take_photo_test_button})
    @Override
    protected void onXmlClick(View v) {
        super.onXmlClick(v);
        switch (v.getId()){
            case R.id.camera_color_test_button:{
                showTitle(R.string.btn_settings_color_camera);

                TestCameraFragment testCameraFragment = new TestCameraFragment();
                testCameraFragment.setArguments(TestCameraFragment.setBundleValue(TestCameraFragment.CAMERA_TYPE_COLOR));
                getActivityBaseFragmentManager().replace(testCameraFragment);
                break;
            }
            case R.id.camera_infrared_test_button:{
                showTitle(R.string.btn_settings_infrared_camera);

                TestCameraFragment testCameraFragment = new TestCameraFragment();
                testCameraFragment.setArguments(TestCameraFragment.setBundleValue(TestCameraFragment.CAMERA_TYPE_INFRARED));
                getActivityBaseFragmentManager().replace(testCameraFragment);
                break;
            }
            case R.id.camera_take_photo_test_button:{
                showTitle(R.string.btn_settings_take_photo_camera);

                TestCameraFragment testCameraFragment = new TestCameraFragment();
                testCameraFragment.setArguments(TestCameraFragment.setBundleValue(TestCameraFragment.CAMERA_TYPE_TAKE_PHOTO));
                getActivityBaseFragmentManager().replace(testCameraFragment);
                break;
            }
        }
    }

    /**
     * 定义一个方法用于 显示标题
     */
    private void showTitle(int title) {
        if (mMainActivity != null) {
            mMainActivity.showToolBarTitle(title);
        }
    }
}
